<template>
  <div id="app">
    <router-view />
    <div id="drag" @touchmove="move" @click="toCustmoer" v-if="flag">
      <img src="./assets/theme-img/icon_person_mail.png" alt="" />
    </div>
  </div>
</template>
<script>
export default {
  name: "App",
  mounted() {},
  data() {
    return {
      flag: true,
    };
  },
  methods: {
    move(e) {
      e.preventDefault();
      let x = e.touches[0].clientX;
      let y = e.touches[0].clientY;
      if (
        x > 50 &&
        x < document.body.clientWidth - 50 &&
        y > 50 &&
        x < document.body.clientHeight - 100
      ) {
        var drag = document.getElementById("drag");
        drag.style.top = y - 50 + "px";
        drag.style.left = x - 50 + "px";
      }
    },
    toCustmoer() {
      this.$router.push("/custmoer");
    },
  },
  watch: {
    $route(n) {
      console.log(n.path);
      if (n.path == "/custmoer") {
        this.flag = false;
      } else {
        this.flag = true;
      }
      // n.path == "/custmoer" ? this.flag = false :this.flag = true;
    },
  },
};
</script>

<style lang="scss">
* {
  margin: 0;
  padding: 0;
  list-style: none;
}
#app,
body,
html {
  width: 100%;
  height: 100%;
}
#drag {
  width: 100px;
  height: 100px;
  background: green;
  border-radius: 50%;
  position: fixed;
  bottom: 50px;
  right: 20px;
  text-align: center;
  line-height: 120px;
}
</style>
